namespace 项目01;
class Student
{
    public string name;
    public string id;
    public string gender;
    private int age;

    public int Age 
    {
        get => age;
        set
        {
            if(value < 1 || value >150)
            {
                age = 0;
            }
            else
            {
                value = age;
            }
        }
    }
    public 手机 手机;

    public string GetInfo()
    {
        return $"姓名：{name}\n身份证：{id}\n性别：{gender}\n年龄：{age}\n手机号码：{手机.号码}\n手机型号：{手机.型号}\n";
    }
    public Student(string 姓名,string 身份证,string 手机型号,string 手机号码)
    {
        name = 姓名;
        id = 身份证;
        获取身份证信息();
        手机 = new 手机(姓名,手机型号,手机号码);
    }

    // public (string 性别 , int 年龄) 获取身份证信息()
    // {
    //     int 身份证倒数第2位 = id[16];
    //     gender = 身份证倒数第2位 % 2 == 0 ? "女" : "男";
    //     DateTime today = DateTime.Now;
    //     string year = id[6..10];
    //     string month = id[10..12];
    //     string day = id[12..14];
    //     DateTime birhday = DateTime.Parse($"{year}/{month}/{day}");
    //     int age = today.Year - birhday.Year;
    //     if(today.Month < birhday.Month) age--;
    //     if(today.Month == birhday.Month && today.Day < birhday.Day) age--;
    //     return (gender,age);
    // }
        public void 获取身份证信息()
    {
        int 身份证倒数第2位 = id[16];
        gender = 身份证倒数第2位 % 2 == 0 ? "女" : "男";
        DateTime today = DateTime.Now;
        string year = id[6..10];
        string month = id[10..12];
        string day = id[12..14];
        DateTime birhday = DateTime.Parse($"{year}/{month}/{day}");
        Age = today.Year - birhday.Year;
        if(today.Month < birhday.Month) Age--;
        if(today.Month == birhday.Month && today.Day < birhday.Day) Age--;
    }
}